// Proper way to initialize and share the Database object
// const logger = require('../services/logger').logger;
const dbcfg = require("../config.json")

// const cn = {
//     host: 'localhost',
//     port: 5432,
//     database: 'my-database-name',
//     user: 'user-name',
//     password: 'user-password'
// };

// Loading and initializing the library:
const pgp = require('pg-promise')({
    // Initialization Options
    connect(client, dc, useCount) {
        const cp = client.connectionParameters;
        // logger.info('Connected to database:', cp.database);
    }
});


// Preparing the connection details:
// const cn = 'postgres://postgres:123@localhost:5432/PostgreSQL10';

// Creating a new database instance from the connection details:
const db = pgp(dbcfg.cn);

// Exporting the database object for shared use:
module.exports = db;